//
//  BridgeScrollView.swift
//  BridgeScrollView
//
//  Created by zjkj on 2024/8/5.
//

import SwiftUI

@available(iOS 13.0, *)
struct BridgeScrollView<Content>: UIViewControllerRepresentable where Content: View {
    
    /// ScrollView配置
    @ObservedObject private var configuration: BridgeScrollConfiguration
    /// 当前ScrollView
    private let content: Content
    
    /// 初始化方法
    /// - Parameters:
    ///   - configuration: 滚动配置
    ///   - content: ScrollView
    init(configuration: BridgeScrollConfiguration, content: Content) {
        self.configuration = configuration
        self.content = content
    }
    
    func makeUIViewController(context: Context) -> BridgeScrollViewController<Content> {
        BridgeScrollViewController(configuration: configuration, contentView: content)
    }
    
    func updateUIViewController(_ uiViewController: BridgeScrollViewController<Content>, context: Context) { 
        uiViewController.freshContentView(content)
    }
}
